-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding agent for caching recipient ids and extra tests for these addi… #35
Conversation
lib/turn_junebug_expressway/agent.ex
Outdated
@@ -0,0 +1,36 @@ | |||
defmodule TurnJunebugExpressway.TurnAgent do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could use a better name. MessageRecipientIdCache
, perhaps?
@@ -11,6 +11,8 @@ defmodule TurnJunebugExpressway.Application do | |||
|
|||
# Define workers and child supervisors to be supervised | |||
children = [ | |||
# Start Agent | |||
{TurnJunebugExpressway.TurnAgent, name: :my_cache}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could name this better here as well.
value = Map.get(message, "recipient_id") | ||
# IO.puts("#{message}") | ||
# IO.puts("#{inspect(key)}, #{inspect(value)}") | ||
TurnJunebugExpressway.TurnAgent.put(:my_cache, key, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TTL needs to be configurable, so we should probably look it up from the application environment and pass it in here.
config/config.exs
Outdated
@@ -5,6 +5,8 @@ | |||
# is restricted to this project. | |||
import Config | |||
|
|||
config :turn_junebug_expressway, :agent, ttl: System.get_env("MESSAGE_TTL", "10000") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure MESSAGE_TTL
really describes what this value is used for.
lib/turn_junebug_expressway/agent.ex
Outdated
@@ -0,0 +1,45 @@ | |||
defmodule TurnJunebugExpressway.MessageRecipientIdCache do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename the file to match the new module name?
lib/turn_junebug_expressway/agent.ex
Outdated
end | ||
|
||
def handle_call({:put, key, value, ttl}, _from, state) do | ||
Process.send_after(self(), {:expire, key}, ttl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing it this way means that if we set the same key multiple times we're not extending the lifetime -- each call will schedule a new expiry. I don't think that's a problem for message ids, but we may want to add a comment noting that behaviour.
…tional implementations